package com.ztom.offer.v2;

/**
 * 青蛙跳台阶问题
 * <p>
 * https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/
 *
 * @author ZhangTao
 */
public class Code08NumWays {

    int mod = 1000000007;

    public int numWays1(int n) {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        return (numWays1(n - 1) + numWays1(n - 2)) % mod;
    }

    public int numWays2(int n) {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
        }
        return dp[n];
    }

    public int numWays(int n) {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        int prepre = 1;
        int pre = 1;
        int cur = 0;
        for (int i = 2; i <= n; i++) {
            cur = (prepre + pre) % mod;
            prepre = pre;
            pre = cur;
        }
        return cur;
    }
}
